<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<style>
</style>
</#assign>
<#assign js>
<script>
	function del(id) {
		layer.confirm('确定删除吗?', {icon: 3, title: '提示'}, function (index) {
			$.ajax({
				type: "POST",
				dataType: "json",
				url: "/category/delete/" + id,
				success: function (res) {
                    layer.msg(res.message, {time: 1000}, function () {
                        location.reload();
                    });

				}
			});
		});
	}
    function init() {
        layer.confirm('确定恢复平台默认物品品类设置，当前分站已经设置的物品品类信息将会被删除?', {icon: 7, title: '警告'}, function (index) {
            $.ajax({
                type: "GET",
                dataType: "json",
                url: "/category/init",
                success: function (res) {
                    layer.msg(res.message, {time: 1000}, function () {
                        location.reload();
                    });

                }
            });
        });
    }


	//tableId,queryId,conditionContainer
	//var userTable;
	var winId="userWin";
	$(function() {
		//init table and fill data
		//userTable = new CommonTable("user_table", "user_list", "searchDiv");

		//button event
		$('button[data-btn-type]').click(function() {
			var action = $(this).attr('data-btn-type');
			var rowId="ceshi";
			switch (action) {
				case 'add':
					modals.openWin({
						winId:winId,
						title:'新增物品品类,物品品类',
						width:'900px',
						url:"/categoryCfg/edit/ceshi"
					});
					break;
				case 'edit':
					if(!rowId){
						modals.info('请选择要编辑的行');
						return false;
					}
					modals.openWin({
						winId:winId,
						title:'编辑物品品类,物品品类【'+userTable.getSelectedRowData().name+'】',
						width:'900px',
						url:"/categoryCfg/edit/"+rowId,
					});
					break;
				case 'delete':
					if(!rowId){
						modals.info('请选择要删除的行');
						return false;
					}
					modals.confirm("是否要删除该行数据？",function(){
						ajaxPost(basePath+"/categoryCfg/delete/"+rowId,null,function(data){
							if(data.success){
								//modals.correct("已删除该数据");
								userTable.reloadRowData();
							}else{
								modals.error("物品品类,物品品类数据被引用，不可删除！");
							}
						});
					})
					break;
			}

		});
		//form_init();
	});
</script>
</#assign>
<@layout title="跑腿业务设置-${title}" active="category">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		${title}
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="/category/index"><i class="fa fa-list-ul"></i> 物品品类</a></li>
		<li class="active"><i class="fa fa-table"></i> 物品品类列表</li>
	</ol>
</section>

<!-- Main content -->
<section class="content">
	<!-- Default box -->
	<div class="box box-primary">
		<div class="box-header">

            <#--<form class="form-horizontal form-edit" method="post" action="/category/index" id="form">
                <div class="form-group" style="margin-top:10px;">
                    <div class="col-sm-2">
                        <input  placeholder="请输入物品品类名称" id="category" name="category" class="form-control" type="text" value="${categorySearch.category!}" >
                    </div>
                    <div class="col-sm-2">
						<select name="type" class="form-control">
							<option value="">请选择所属类型</option>
							<option value="1" <#if categorySearch.type??&&categorySearch.type ==1>selected</#if>>帮我送</option>
							<option value="2" <#if categorySearch.type??&&categorySearch.type ==2>selected</#if>>帮我取</option>
							<option value="3" <#if categorySearch.type??&&categorySearch.type ==3>selected</#if>>随意购</option>
						</select>
                    </div>
                    <div class="btn-group">
                        <button type="submit" class="btn btn-primary" data-btn-type="search">查询</button>
                        <button type="button" class="btn btn-default" data-btn-type="reset" onclick="javascript:$('#form')[0].reset();">重置</button>
                    </div>
				</div>
			</form>-->

        <@shiro.hasPermission name="system:category:add">
			<a class="btn btn-sm btn-success" href="/category/add/${categorySearch.type}">新增</a>
        </@shiro.hasPermission>
		<#--<@shiro.hasPermission name="system:category:init">
			<a class="btn btn-sm btn-info" onclick="init()">恢复平台默认配置</a>
		</@shiro.hasPermission>-->
		</div>
		<div class="box-body">
			<table class="table table-striped">
				<tr>
					<th></th>
					<th>分类名称</th>
                    <th>所属大类</th>
					<th>创建人</th>
					<th>创建时间</th>
					<th>操作</th>
				</tr>
                <#list pageInfo.list as item>
                <tr>
					<td >${item.id!}</td>
					<td >${item.category!}</td>
                    <td  >
						<#if item.type== 1>
							帮我送
						<#elseif item.type== 2>
							帮我取
						<#else >
							随意购
						</#if>

					</td>
					<td >${item.createBy!}</td>
                    <td >${(item.createAt?string('yyyy-MM-dd HH:mm:ss'))!}</td>
					<td>
                    <@shiro.hasPermission name="system:category:edit">
                        <a class="btn btn-sm btn-primary" href="/category/edit/${item.id}" data-btn-type="edit">编辑</a>
                    </@shiro.hasPermission>
                    <@shiro.hasPermission name="system:category:delete">
                        <button class="btn btn-sm btn-danger" onclick="del('${item.id}')">删除</button>
                    </@shiro.hasPermission>
					</td>
				</tr>
                </#list>
			</table>
		</div>
		<!-- /.box-body -->
		<div class="box-footer clearfix">
            <@macro.page pageInfo=pageInfo url="/category/index?" />
		</div>
	</div>
	<!-- /.box -->

</section>
<!-- /.content -->
</@layout>
